﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace DeHeng_Mes.Utils
{
    class HashUtils {
        public static long GetHashAsInt(string barcode, int tableCount) {
            using (var sha256 = SHA256.Create()) {
                byte[] bytes = Encoding.UTF8.GetBytes(barcode);
                byte[] hashBytes = sha256.ComputeHash(bytes);
                // 取前4个字节并手动组合为int，确保大端序  
                int hashInt = (hashBytes[0] << 24) | (hashBytes[1] << 16) | (hashBytes[2] << 8) | hashBytes[3];
                return (hashInt & 0xFFFFFFFF) % tableCount;
            }
        }
    }
}
